package eu.dicodeproject.analysis.histogram;

import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.mahout.common.IntegerTuple;

import java.io.IOException;

/**
 * Sums all the values assigned to pattern/bucket keys.
 */
public class HistogramReducer extends TableReducer<IntegerTuple, IntWritable, IntegerTuple> {
  @Override
  protected void reduce(IntegerTuple keyin, Iterable<IntWritable> values, Context context)
      throws IOException, InterruptedException {
    int result = 0;
    for (IntWritable i : values) {
      result += i.get();
    }
    context.write(keyin, new IntWritable(result));
  }

}
